package com.dz.lm.common.util;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

public class DzCache {
	private static Cache<String, Object> cacheBuilder = CacheBuilder.newBuilder().concurrencyLevel(100)
			.softValues()
			.expireAfterAccess(1, TimeUnit.DAYS)
			.maximumSize(1000)
			.build();
	public static ConcurrentMap<String, Object> cacheMap = DzCache.cacheBuilder.asMap(); // 构建Map对象;

	public static synchronized void setCacheCode(String key, Object value) {
		cacheMap.put(key, value);
	}

	public static synchronized Object getCacheCode(String key) {
		return cacheMap.get(key);
	}

	public static void main(String[] args) throws Exception {
		List<String> idList = new ArrayList<String>();
		idList.add("0001");
		idList.add("0002");
		idList.add("0003");
		idList.get(0);
		if (idList.get(0) != null) {
			System.out.println(idList.size());
			idList.remove(0);
			System.out.println(idList.size());
		}
		
		cacheMap.put("11", "1111");
		cacheMap.put("22", "2222");
		System.out.println(cacheMap.containsKey("11"));
		System.out.println(cacheMap.containsKey("22"));
		Thread.sleep(3001);
		cacheMap.put("33", "3333");
		System.out.println(cacheMap.containsKey("11"));
		System.out.println(cacheMap.containsKey("22"));
		System.out.println(cacheMap.containsKey("33"));
	}
}
